package com.fdb.efp.console.api.rest;

import com.fdb.basic.framework.core.constant.DataRuleType;
import com.fdb.basic.framework.core.constant.PubConstant;
import com.fdb.basic.framework.core.constant.ResponseData;
import com.fdb.basic.framework.web.controller.AbstractController;
import com.fdb.efp.console.service.facade.SRoleDataRuleService;
import com.fdb.efp.console.service.facade.LmtPrdContService;
import com.fdb.efp.console.service.vo.LmtPrdContVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 授信额度查询
 *
 * @author wanglihua
 * @version 1.0
 * @since 2019年3月15日 上午9:59:29
 */

@RestController
@RequestMapping("/api")
public class LmtPrdContController extends AbstractController {

    @Autowired
    @Qualifier("lmtPrdContService")
    private LmtPrdContService lmtPrdContService;

    @Autowired
    @Qualifier("sRoleDataRuleService")
    private SRoleDataRuleService sRoleDataRuleService;


    @PostMapping(value = "/lmt/prd/conts")
    public @ResponseBody ResponseData<List<LmtPrdContVO>> queryAllOwner(@RequestBody LmtPrdContVO vo) {
        List<LmtPrdContVO> outputVo = null;
        // 根据用户角色获取用户权限方案
        Map<String, String> dataRuleTypeMap = sRoleDataRuleService.getDataRuleType(httpRequest.getRequestURI(), getUserRoles());
        vo.setPrdCodebyBaseInfo(dataRuleTypeMap == null ? null : dataRuleTypeMap.get(PubConstant.PRD_CODE));
        DataRuleType dataRuleType = DataRuleType.getDataRuleType(dataRuleTypeMap == null ? null : dataRuleTypeMap.get(PubConstant.PERMIS_TYPE));
        setUserInfoToVO(vo);
        // 根据权限方案调用不同的方法进行数据查询
        switch (dataRuleType) {
            case Owner:
                outputVo = lmtPrdContService.queryAllOwner(vo);
                break;
            case CurrOrg:
                outputVo = lmtPrdContService.queryAllCurrOrg(vo);
                break;
            case CurrDownOrg:
                outputVo = lmtPrdContService.queryAllCurrDownOrg(vo);
                break;
            case CurrOwnerPrd:
                outputVo = lmtPrdContService.queryAllCurrOwnerPrd(vo);
                break;
            default:
                outputVo = lmtPrdContService.queryAllOwner(vo);
                break;
        }
        return getResponseData(outputVo);
    }
}
